package chapter5;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description:  出十个随即加法（加数为1-15的整数）  显示正确答案个数及时间
 * Date:2021/4/3
 * ***************************************************************
 */
public class exc5_2 {
	public static void main(String[] args) {
		final int NUMBER_OF_QUESTIONS=10;
		int correctCount=0;			//count  the number of correct questions
		int count=0;				//count the number of questions
		long startTime =System.currentTimeMillis();
		String output="";		//output string is initially empty
		
		Scanner input=new Scanner(System.in);
		
		while(count<NUMBER_OF_QUESTIONS) {
			int number1=(int)(Math.random()*16);
			int number2=(int)(Math.random()*16);
			
			System.out.println("No."+(count+1)+" : "+"What is "+number1+"+ "+number2+" ?");
			int ans=input.nextInt();
			
			if(ans==(number1+number2)) {
				correctCount++;
				count++;
				System.out.println("You are correct !");
				output+=number1+"+ "+number2+" = "+(number1+number2)+"    correct\n";

			}else {
				count++;
				System.out.println("You answer is wrong.");
				System.out.println(number1+"+ "+number2+"  should  be "+(number1+number2));
				output+=number1+"+ "+number2+" = "+(number1+number2)+"   wrong\n";

			}
						
		}/*end of while */
		
		System.out.print("*************************\n"+"Correct count is "+correctCount+"\n");
		System.out.println("Test time is "+(System.currentTimeMillis()-startTime)/1000+" seconds.");
		System.out.print(output);
		
		
	}

}
